package cn.sciento.boot.data.change.dto;

import io.choerodon.mybatis.domain.EntityTable;
import net.sf.jsqlparser.JSQLParserException;
import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.plugin.Invocation;

public class MybatisInvocation {
  private MappedStatement mappedStatement;
  
  private Object parameter;
  
  private Executor executor;
  
  private EntityTable table;
  
  private SqlParserInfo sqlParserInfo;
  
  private BoundSql boundSql;
  
  private Invocation invocation;
  
  private Boolean paramRewritedFlag = Boolean.valueOf(false);
  
  public static MybatisInvocation getInstance(Invocation invocation, MappedStatement mappedStatement, Object parameter, Executor executor, EntityTable table) throws JSQLParserException {
    MybatisInvocation mybatisInvocation = new MybatisInvocation();
    mybatisInvocation.setInvocation(invocation);
    mybatisInvocation.setMappedStatement(mappedStatement);
    mybatisInvocation.setExecutor(executor);
    mybatisInvocation.setParameter(parameter);
    mybatisInvocation.setTable(table);
    mybatisInvocation.setBoundSql(mappedStatement.getBoundSql(parameter));
    mybatisInvocation.setSqlParserInfo(SqlParserInfo.getInstance(mappedStatement.getBoundSql(parameter).getSql(), mappedStatement
          .getSqlCommandType()));
    return mybatisInvocation;
  }
  
  public MappedStatement getMappedStatement() {
    return this.mappedStatement;
  }
  
  public void setMappedStatement(MappedStatement mappedStatement) {
    this.mappedStatement = mappedStatement;
  }
  
  public Object getParameter() {
    return this.parameter;
  }
  
  public void setParameter(Object parameter) {
    this.parameter = parameter;
  }
  
  public Executor getExecutor() {
    return this.executor;
  }
  
  public void setExecutor(Executor executor) {
    this.executor = executor;
  }
  
  public EntityTable getTable() {
    return this.table;
  }
  
  public void setTable(EntityTable table) {
    this.table = table;
  }
  
  public SqlParserInfo getSqlParserInfo() {
    return this.sqlParserInfo;
  }
  
  public void setSqlParserInfo(SqlParserInfo sqlParserInfo) {
    this.sqlParserInfo = sqlParserInfo;
  }
  
  public BoundSql getBoundSql() {
    return this.boundSql;
  }
  
  public void setBoundSql(BoundSql boundSql) {
    this.boundSql = boundSql;
  }
  
  public Invocation getInvocation() {
    return this.invocation;
  }
  
  public void setInvocation(Invocation invocation) {
    this.invocation = invocation;
  }
  
  public Boolean getParamRewritedFlag() {
    return this.paramRewritedFlag;
  }
  
  public void setParamRewritedFlag(Boolean paramRewritedFlag) {
    this.paramRewritedFlag = paramRewritedFlag;
  }
}
